<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>广东省传播平台-媒体计划投放量录入页</title>
		<link rel="stylesheet" type="text/css" href="<%=path%>/css/common.css" />
		<link rel="stylesheet" type="text/css" href="<%=path%>/css/tag.css" />
		<script type="text/javascript" src="<%=path%>/js/jquery-1.7.2.js"></script>
		<link href="<%=path%>/js/My97DatePicker/skin/WdatePicker.css"
			rel="stylesheet" type="text/css" />
		<link type="text/css"
			href="<%=path%>/js/jquery-ui-1.8.21.custom/css/smoothness/jquery-ui-1.8.21.custom.css"
			rel="stylesheet" />
		<script type="text/javascript"
			src="<%=path%>/js/jquery-ui-1.8.21.custom/js/jquery-ui-1.8.21.custom.min.js"></script>
		<script type="text/javascript"
			src="<%=request.getContextPath()%>/js/My97DatePicker/WdatePicker.js"></script>
		<script type="text/javascript">
		
		
		$(function(){
        	//setTimeout(function(){alert("服务器异常，请刷新后重试！");},10000);
			var city = $('#city').val();
			var year = $('#year').val();
			 
	        //selectNav('nav7');
			var costType = $('#costType').val();
			var key = $('#keyCostSubType').val();

			if(costType != 0)
			{
				change('1');
				$.ajax({
		        	url:"getCostSubtype",
		        	data:{'costType':costType},
		        	datatype: "json",
		        	cache:false,	  
		        	success : function(data) { 
		        		$("#costSubtype").html("");
		        		var headid = 0;
		        		var headvalue = "请选择";
		        		$("#costSubtype").append($("<option value='" + headid + "'>" + headvalue + "</option>"));
		       		    $.each(data,function(i,value){
		       			    var id=value.id;
		       			    var name=value.datavalue;
		       			    if(id==key)
		       			    {
		       			    	$("#costSubtype").append($("<option value='" + id + "' selected>" + name + "</option>"));
		       			    }
		       			    else
		       			    {
		       					$("#costSubtype").append($("<option value='" + id + "'>" + name + "</option>"));
		       			    }
		       			});            	                   	                             	                    	                                                             
		            },
		        	error:function()
		        	{
		        		alert("服务器异常，请刷新后重试！");
						return false;
			        }   
		        });

				$.ajax({
		        	url:"getMedia",
		        	cache:false,
		        	data:{'city':city,'year':year},
		        	datatype: "json",	  
		        	success : function(data) { 
		        		$("#xiangmuId").html("");
		        		//if(data == null || data.length <= 0){
							//alert("没有可选媒体！");
							//return false;
						//}else{
		       		    $.each(data,function(i,value){
		       			    var id=value.mediaID;
		       			    var name=value.mediaName;
		       			    var price = value.idPrice;
		       			    var idName=id+","+name+"*"+price;
		       				$("#xiangmuId").append($("<option value='" + idName + "'>" + name + "</option>"));
		       			});             	                   	                             	                    	                                                             
		                 // }
		        	},
		        	error:function()
		        	{
		        		alert("服务器异常，请刷新后重试！");
						return false;
			        }    
		        });
		        
				$("#entity").html("");   
			    var html = "";
				html += 
					"<tr class='bg1'>"+
						"<th rowspan=1>计划投放量总和</th>"+
						"<th rowspan=1>固定资源</th>"+
						"<th rowspan=1>浮动资源</th>"+
						"<th rowspan=1>购买资源</th>"+
						"<th colspan=6>赠送资源</th>"+
				    "</tr>"+
					"<tr>"+
						"<td  rowspan=3  style='width: 10%;'><input style='width: 100px;border-style: none;' type='text' id='planTotalAmount' name='sourcePlanYear.planTotalAmount' readonly='readonly' value='"+'<fmt:formatNumber value="${sourcePlanYear.planTotalAmount}" type="number" pattern="##0.000" />'+"'/></td>"+
						"<td  rowspan=3 style='width: 10%;'><input style='width: 100px;' type='text' id='fixSourceAmount' name='sourcePlanYear.fixSourceAmount' value='"+'<fmt:formatNumber value="${sourcePlanYear.fixSourceAmount}" type="number" pattern="##0.000" />'+"' maxlength='12'/></td>"+
						"<td  rowspan=3 style='width: 10%;'><input style='width: 100px;' type='text' id='floatSourceAmount' name='sourcePlanYear.floatSourceAmount' value='"+'<fmt:formatNumber value="${sourcePlanYear.floatSourceAmount}" type="number" pattern="##0.000" />'+"' maxlength='12'/></td>"+
						"<td  rowspan=3 style='width: 10%;'><input style='width: 100px;' type='text' id='unPromotionAmount' name='sourcePlanYear.unPromotionAmount' value='"+'<fmt:formatNumber value="${sourcePlanYear.unPromotionAmount}" type="number" pattern="##0.000" />'+"' maxlength='12'/></td>"+
						"<th style='width: 10%;' align='right'>常规赠送金额 &nbsp;</th>"+
						"<td style='width: 10%;'><input style='width: 100px;' type='text' id='promotionAmount' name='sourcePlanYear.promotionAmount' value='"+'<fmt:formatNumber value="${sourcePlanYear.promotionAmount}" type="number" pattern="##0.000" />'+"' maxlength='12'/></td>"+
						"<th style='width: 10%;' align='right'>增量赠送金额&nbsp;</th>"+
						"<td><input style='width:100px;' type='text' id='increPromotionAmount' name='sourcePlanYear.increPromotionAmount' value='"+'<fmt:formatNumber value="${sourcePlanYear.increPromotionAmount}" type="number" pattern="##0.000" />'+"' maxlength='12'/></td>"+
						"<th style='width: 12%;' align='right'>年底一次性返还金额&nbsp;</th>"+
						"<td><input style='width: 100px;' type='text' id='returnSourceAmount' name='sourcePlanYear.returnSourceAmount' value='"+'<fmt:formatNumber value="${sourcePlanYear.returnSourceAmount}" type="number" pattern="##0.000" />'+"' maxlength='12'/></td>"+
					    "</tr>"+
					"<tr>"+
						"<th style='width: 10%;' align='right'>常规资源折扣率&nbsp;</th>"+
						"<td><input style='width: 100px;' type='text' id='promotionUsedRatio' name='sourcePlanYear.promotionUsedRatio' value='${sourcePlanYear.promotionUsedRatio}' maxlength='9'/></td>"+
						"<th style='width: 10%;' align='right'>增量资源折扣率&nbsp;</th>"+
							"<td><input style='width: 100px;' type='text' id='increPromotionUsedRatio' name='sourcePlanYear.increPromotionUsedRatio' value='${sourcePlanYear.increPromotionUsedRatio}' maxlength='9'/></td>"+
						"<th style='width: 10%;' align='right'>返还资源折扣率&nbsp;</th>"+
									"<td><input style='width: 100px;' type='text' id='returnSourceUsedRatio' name='sourcePlanYear.returnSourceUsedRatio' value='${sourcePlanYear.returnSourceUsedRatio}' maxlength='9'/></td>"+
					"</tr>"+
					"<tr>"+
						"<th style='width: 10%;' align='right'>常规资源有效期&nbsp;</th>"+
						"<td> <input type='text' id='promotion' class='text Wdate' name='sourcePlanYear.promotionAmountTime' id='contractStartTime' value='${sourcePlanYear.promotionAmountTime}' onfocus='WdatePicker({isShowClear:false,readonly:true})' style='width: 100px;' /></td>"+
						"<th style='width: 10%;' align='right'>增量资源有效期&nbsp;</th>"+
						"<td> <input type='text' id='increPro' class='text Wdate' name='sourcePlanYear.increPromotionAmountTime' id='contractStartTime' value='${sourcePlanYear.increPromotionAmountTime}' onfocus='WdatePicker({isShowClear:false,readonly:true})' style='width: 100px;' /></td>"+
						"<th style='width: 10%;' align='right'>返还资源有效期&nbsp;</th>"+
						"<td> <input type='text' id='returnSource' class='text Wdate' name='sourcePlanYear.returnSourceAmountTime' id='contractStartTime' value='${sourcePlanYear.returnSourceAmountTime}' onfocus='WdatePicker({isShowClear:false,readonly:true})' style='width: 100px;' /></td>"+
					"</tr>"
					$("#entity").html(html);   
				    $("#bottom1").attr("style","display:block"); 
				    $("#bottom3").attr("style","display:none"); 
				    var htm = "";
				    $("#estname").html("媒体名称:");
	       			htm += 
						"<td width='226' style='width:225px;'>"+
						"<input id='dialog_link' name='sourcePlanYear.mediaName' class='text' type='text'  style='width:225px;' readonly='readonly' value='${sourcePlanYear.mediaName}'/>"+
						"<input id='dialog_id' name='sourcePlanYear.mediaID' class='text' type='hidden'  style='width:225px;' readonly='readonly'  value='${sourcePlanYear.mediaID}' />"+
					    "<input id='dialog_idprice' name='sourcePlanYear.id_price' class='text' type='hidden'  style='width:225px;' readonly='readonly' value='${sourcePlanYear.id_price}'/>"+
						"</td>"
					$("#estvalue").html(htm);
					$('#dialog').dialog({
						autoOpen: false,
						width: 400,
						height: 410,
						title: "媒体选择",
						show: "blind",
						hide:"slide",
					    modal: true, 
					    overlay: { opacity: 0.5, background: "black" }	
					});
					$('#dialog_link').click(function(){
						//alert($('#xiangmuId').children('option').length);
						if($('#xiangmuId').children('option').length==0)
					    {
					    	alert("没有可选媒体！");
							return false;
						}
						if($('#city').val()!=0)
						{
							$('#dialog').dialog('open');
						}
						else
						{
							alert("请选择地市");
						}
					});
				
			}

			//$('#costSubtype').change(function(){costSubtySelect()});
			$("#dialog").bind("dialogclose", function() {
				$('#mediaName').val('');
				$.ajax({
		        	url:"getMedia",
		        	cache:false,
		        	data:{'city':city,'year':year},
		        	datatype: "json",	  
		        	success : function(data) { 
		        		$("#xiangmuId").html("");
		        		//if(data == null || data.length <= 0){
							//alert("没有可选媒体！");
							//return false;
						//}else{
		       		    $.each(data,function(i,value){
		       			    var id=value.mediaID;
		       			    var name=value.mediaName;
		       			    var price = value.idPrice;
		       			    var idName=id+","+name+"*"+price;
		       				$("#xiangmuId").append($("<option value='" + idName + "'>" + name + "</option>"));
		       			});             	                   	                             	                    	                                                             
		                 // }
		        	},
		        	error:function()
		        	{
		        		alert("服务器异常，请刷新后重试！");
						return false;
			        }    
			     });
			});
				
          });


		function costSubtySelect()
		{
			var city = $('#city').val();
			var year = $('#year').val();
			var costSubType = $("#costSubtype").val();
			var costType = $('#costType').val(); 
			$.ajax({
		       	url:"selectentity.action",
		       	data:{'costSubType':costSubType,'costType':costType},
		       	datatype: "json",
		       	cache:false,	  
		       	success : function(data) { 
		       		var html = "";
		       		var htm = "";
		       		if(data ==1)
		            {
		       		    //清空当前表格中的内容
						$("#entity").html("");
						$("#estvalue").html("");
						$("#estname").html("预算值:");
		       			html += 
							"<td width='226' style='width:225px;'>"+
							    "<input id='estimated' name='sourcePlanYear.budget' class='text' type='text'  style='width:225px;' maxlength='12'/>"+
							"</td>"
						$("#estvalue").html(html);		
		       			$("#bottom2").attr("style","display:block");
						$("#bottom1").attr("style","display:none");
						$("#head").attr("style","display:none");
						$("#bottom3").attr("style","display:none");
					}
					if(data ==2){			
						//清空当前表格中的内容
						$("#entity").html("");
						$("#estname").html("");
						$("#estvalue").html("");
						$("#bottom1").attr("style","display:block");
						$("#bottom2").attr("style","display:none");
						$("#head").attr("style","display:block");
						$("#bottom3").attr("style","display:none");
						html += 
						"<tr class='bg1'>"+
							"<th rowspan=1>计划投放量总和</th>"+
							"<th rowspan=1>固定资源</th>"+
							"<th rowspan=1>浮动资源</th>"+
							"<th rowspan=1>购买资源</th>"+
							"<th colspan=6>赠送资源</th>"+
					    "</tr>"+
						"<tr>"+
							"<td  rowspan=3  style='width: 10%;'><input style='width: 100px;border-style: none;' type='text' id='planTotalAmount' name='sourcePlanYear.planTotalAmount' readonly='readonly' value='0.0'/></td>"+
							"<td  rowspan=3 style='width: 10%;'><input style='width: 100px;' type='text' id='fixSourceAmount' name='sourcePlanYear.fixSourceAmount' value='0.0' maxlength='12'/></td>"+
							"<td  rowspan=3 style='width: 10%;'><input style='width: 100px;' type='text' id='floatSourceAmount' name='sourcePlanYear.floatSourceAmount' value='0.0' maxlength='12'/></td>"+
							"<td  rowspan=3 style='width: 10%;'><input style='width: 100px;' type='text' id='unPromotionAmount' name='sourcePlanYear.unPromotionAmount' value='0.0' maxlength='12'/></td>"+
							"<th style='width: 10%;' align='right'>常规赠送金额 &nbsp;</th>"+
							"<td style='width: 10%;'><input style='width: 100px;' type='text' id='promotionAmount' name='sourcePlanYear.promotionAmount' value='0.0' maxlength='12'/></td>"+
							"<th style='width: 10%;' align='right'>增量赠送金额&nbsp;</th>"+
							"<td><input style='width:100px;' type='text' id='increPromotionAmount' name='sourcePlanYear.increPromotionAmount' value='0.0' maxlength='12'/></td>"+
							"<th style='width: 12%;' align='right'>年底一次性返还金额&nbsp;</th>"+
							"<td><input style='width: 100px;' type='text' id='returnSourceAmount' name='sourcePlanYear.returnSourceAmount' value='0.0' maxlength='12'/></td>"+
						    "</tr>"+
						"<tr>"+
							"<th style='width: 10%;' align='right'>常规资源折扣率&nbsp;</th>"+
							"<td><input style='width: 100px;' type='text' id='promotionUsedRatio' name='sourcePlanYear.promotionUsedRatio' value='0.0' maxlength='9'/></td>"+
							"<th style='width: 10%;' align='right'>增量资源折扣率&nbsp;</th>"+
								"<td><input style='width: 100px;' type='text' id='increPromotionUsedRatio' name='sourcePlanYear.increPromotionUsedRatio' value='0.0' maxlength='9'/></td>"+
							"<th style='width: 10%;' align='right'>返还资源折扣率&nbsp;</th>"+
										"<td><input style='width: 100px;' type='text' id='returnSourceUsedRatio' name='sourcePlanYear.returnSourceUsedRatio' value='0.0' maxlength='9'/></td>"+
						"</tr>"+
						"<tr>"+
							"<th style='width: 10%;' align='right'>常规资源有效期&nbsp;</th>"+
							"<td> <input type='text' id='promotion' class='text Wdate' name='sourcePlanYear.promotionAmountTime' id='contractStartTime' value='${promotionAmountTime}' onfocus='WdatePicker({isShowClear:false,readonly:true})' style='width: 100px;' /></td>"+
							"<th style='width: 10%;' align='right'>增量资源有效期&nbsp;</th>"+
							"<td> <input type='text' id='increPro' class='text Wdate' name='sourcePlanYear.increPromotionAmountTime' id='contractStartTime' value='${increPromotionAmountTime}' onfocus='WdatePicker({isShowClear:false,readonly:true})' style='width: 100px;' /></td>"+
							"<th style='width: 10%;' align='right'>返还资源有效期&nbsp;</th>"+
							"<td> <input type='text' id='returnSource' class='text Wdate' name='sourcePlanYear.returnSourceAmountTime' id='contractStartTime' value='${returnSourceAmountTime}' onfocus='WdatePicker({isShowClear:false,readonly:true})' style='width: 100px;' /></td>"+
						"</tr>"
						$("#entity").html(html);
						$("#estname").html("媒体名称:");
		       			htm += 
							"<td width='226' style='width:225px;'>"+
							"<input id='dialog_link' name='sourcePlanYear.mediaName' class='text' type='text'  style='width:225px;' readonly='readonly'/>"+
							"<input id='dialog_id' name='sourcePlanYear.mediaID' class='text' type='hidden'  style='width:225px;' readonly='readonly'/>"+
						    "<input id='dialog_idprice' name='sourcePlanYear.id_price' class='text' type='hidden'  style='width:225px;' readonly='readonly'/>"+
							"</td>"
						$("#estvalue").html(htm);
                        //查询媒体列表
						$.ajax({
				        	url:"getMedia",
				        	cache:false,
				        	data:{'city':city,'year':year},
				        	datatype: "json",	  
				        	success : function(data) { 
				        		$("#xiangmuId").html("");
				        		//if(data == null || data.length <= 0){
									//alert("没有可选媒体！");
									//return false;
								//}else{
				       		    $.each(data,function(i,value){
				       			    var id=value.mediaID;
				       			    var name=value.mediaName;
				       			    var price = value.idPrice;
				       			    var idName=id+","+name+"*"+price;
				       				$("#xiangmuId").append($("<option value='" + idName + "'>" + name + "</option>"));
				       			});             	                   	                             	                    	                                                             
				                 // }
				        	},
				        	error:function()
				        	{
				        		alert("服务器异常，请刷新后重试！");
								return false;
					        }    
					     });
					     
						$('#dialog').dialog({
							autoOpen: false,
							width: 380,
							height: 465,
							show: "blind",
							hide:"slide",
							resizable: false,
							//position: [800,220]  //显示位置
							modal: true, overlay: { opacity: 0.5, background: "black" },
							
						});
						$('#dialog_link').click(function(){
							//alert($('#xiangmuId').children('option').length);
							if($('#xiangmuId').children('option').length==0)
						    {
						    	alert("没有可选媒体！");
								return false;
							}
							if($('#city').val()!=0)
							{
							$('#dialog').dialog('open');
							//return false;
							}
							else
							{
								alert("请选择地市");
							}
						})
					}
		     },
		       	error:function()
		    	{
		    		alert("服务器异常，请刷新后重试！");
					return false;
		        }     
		    }); 
		}
         

     function findAllContract()
     {
		 var time = new Date().getTime();
		 var medianame = $.trim($("#mediaName").val())
		 $.ajax({
	       	url:"findAllMediasummByName!findMedia.action",
	       	data:{mediaName : medianame, city : $('#city').val(),year:$('#year').val(),timer:time},
	       	datatype: "json",
	       	cache:false,	  
	       	success : function(data) 
	       	{ 
	       		$("#xiangmuId").html("");
	       		$.each(data,function(i,value){
	   			    var id=value.mediaID;
	   			    var name=value.mediaName;
	   			    var price = value.idPrice;
	   			    var idName=id+","+name+"*"+price;
	   				$("#xiangmuId").append($("<option value='" + idName + "'>" + name + "</option>"));
	   			});
	        },
	        error: function()
	        {
	        	 alert("没有可选媒体！");
		    }
		 });
     }
    function xiangmuDBlclick()
    {
		var media = String($("#xiangmuId").val());
		var start = media.indexOf(',');
		var end = media.indexOf('*');
		$("#dialog_link").val(media.substring(start+1,end));
		$("#dialog_id").val(media.substring(0,start));
		$("#dialog_idprice").val(media.substring(end+1));
		$("#dialog").dialog("close");
    }
    function change(m)
    {
	    if(m==1)
		{
		var city = $('#city').val();
		var year = $('#year').val();
		 $.ajax({
	        	url:"getMedia",
	        	data:{'city':city,'year':year},
	        	datatype: "json",
	        	cache:false,	  
	        	success : function(data) { 
	        		$("#xiangmuId").html("");
	        	if(data == null || data.length <= 0){
	    			alert("没有可选媒体！");
	    		 }
	    		 else
	    	     {
	       		    $.each(data,function(i,value){
	       			    var id=value.mediaID;
	       			    var name=value.mediaName;
	       			    var price = value.idPrice;
	       			    var idName=id+","+name+"*"+price;
	       				$("#xiangmuId").append($("<option value='" + idName + "'>" + name + "</option>"));
	       			});             	                   	                             	                    	                                                             
	              }
	        	},
	        	error:function()
	        	{
	        		alert("没有可选媒体！");
					return false;
		        }    
	     });
		}
		if(m==2)
		{	
			var costType = $('#costType').val();
			$.ajax({
	        	url:"getCostSubtype",
	        	data:{'costType':costType},
	        	datatype: "json",
	        	cache:false,	  
	        	success : function(data) { 
	        		$("#costSubtype").html("");
	        		 if(data == null || data.length <= 0){
	        			alert("没有可选费用子类！");
	        			return false;
	        		 }
	        		 else
	        	     {
		        		var headid = 0;
		        		var headvalue = "请选择";
		        		$("#costSubtype").append($("<option value='" + headid + "'>" + headvalue + "</option>"));
		       		    $.each(data,function(i,value){
		       			    var id=value.id;
		       			    var name=value.datavalue;
		       				$("#costSubtype").append($("<option value='" + id + "'>" + name + "</option>"));
		       			});            	                   	                             	                    	                                                             
	                  }  
	        	},
	        	error:function()
	        	{
	        		alert("没有可选费用子类！");
					return false;
		        }  
		     });
		}	
      }




	function mediaNameRes()
	{
		$('#mediaName').attr("value",'');
	}



//时间对比
function timeCheck(a, b) {
    var arr = a.split("-");
    var starttime = new Date(arr[0], arr[1], arr[2]);
    var starttimes = starttime.getTime();

    var arrs = b.split("-");
    var lktime = new Date(arrs[0], arrs[1], arrs[2]);
    var lktimes = lktime.getTime();

    if (starttimes > lktimes) {
        return false;
    }
    else{
        return true;
     }
}

function doSubmit(m)
{
	if(m==2)
	{     
		//判断特殊字符
		var myReg = /^[^@\/\'\\\"#$%&\^\*<>]+$/;
		
		
		//开始时间
		var myDate = new Date();
		var y =myDate.getFullYear();    //获取完整的年份(4位,1970-????)
		var m =myDate.getMonth()+1;       //获取当前月份(0-11,0代表1月)
		var d =myDate.getDate();
		if(m<10){
			m='0'+m;
		}
		if(d<10){
			d='0'+d;
		}
		var norwDate = '${nowDate}';  

	
	    var returnSource = $.trim($("#returnSource").val());
	    var increPro = $.trim($("#increPro").val());
	    var promotion = $.trim($("#promotion").val());

	    //规范数字
		var numReg = /^\d+(\.\d{1,3})?$/;
		//0-100数字
		var numReg2 = /^(?:(?!0\d)\d{1,2}(?:\.\d{1,2})?|100(?:\.0{1,2})?)$/;
		//var numReg = /[^\d\.]/g;
		//var numReg = /([0]|([1-9]\\d+)([.]{0,1}\d*$/;
		//var numReg = /^(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*))$/;
		if($('#city').val()==0)
		{
			alert('地市不能为空');
			return false;
		}
		 if($('#costType').val()==0)
		{
			alert('费用类型不能为空!');
			return false;
		}
		 if($("#costSubtype").val()==0)
		{
			alert('费用子类不能为空!');
			return false;
		}
		 if($('#dialog_link').val().length==0)
		{
			alert('媒体名称不能为空!');
			return false;
		}
		 if(isNaN($('#fixSourceAmount').val()) ||!numReg.test($('#fixSourceAmount').val()))
		{
			alert('固定资源大小必须为数字!');
			return false;
		}		
		 if($('#fixSourceAmount').val().length==0)
		{
			alert('固定资源不能为空!');
			return false;
		}
		 if($('#fixSourceAmount').val().indexOf(' ')>=0)
		{
			alert('固定资源不能存在空格!');
			return false;
		}
 		if(isNaN($('#floatSourceAmount').val()) || !numReg.test($('#floatSourceAmount').val()))
		{
			alert('浮动资源大小必须为数字!');
			return false;
		}
		 if($('#floatSourceAmount').val().length==0)
		{
			alert('浮动资源不能为空!');
			return false;
		}
		 if($('#floatSourceAmount').val().indexOf(' ')>=0)
		{
			alert('浮动资源不能存在空格!');
			return false;
		}
		 if(isNaN($('#unPromotionAmount').val())  || !numReg.test($('#unPromotionAmount').val()))
		{
			alert('购买资源大小必须为数字!');
			return false;
		}
		 if($('#unPromotionAmount').val().length==0)
		{
			alert('购买资源不能为空!');
			return false;
		}
		 if($('#unPromotionAmount').val().indexOf(' ')>=0)
		{
			alert('购买资源不能存在空格!');
			return false;
		}
		 if(isNaN($('#promotionAmount').val()) || !numReg.test($('#promotionAmount').val()))
		{
			alert('常规赠送资源大小必须为数字!');
			return false;
		}
		 if($('#promotionAmount').val().length==0)
		{
			alert('常规赠送资源不能为空!');
			return false;
		}
		 if($('#promotionAmount').val().indexOf(' ')>=0)
		{
			alert('常规赠送资源不能存在空格!');
			return false;
		}
		if(isNaN($('#promotionUsedRatio').val())|| !numReg2.test($('#promotionUsedRatio').val()) )
		{
			alert('常规资源折扣率必须为0~100的数字!');
			return false;
		}
		 if($('#promotionUsedRatio').val().length==0)
		{
			alert('常规资源折扣率不能为空!');
			return false;
		}
		 if($('#promotionUsedRatio').val().indexOf(' ')>=0)
		{
			alert('常规资源折扣率不能存在空格!');
			return false;
		}
		 if($('#increPromotionAmount').val().length==0)
		{
			alert('增量赠送资源不能为空!');
			return false;
		}
		 if($('#increPromotionAmount').val().indexOf(' ')>=0)
		{
			alert('增量赠送资源不能存在空格!');
			return false;
		}
		if(isNaN($('#increPromotionAmount').val())  || !numReg.test($('#increPromotionAmount').val()))
		{
			alert('增量赠送资源必须为数字!');
			return false;
		}
		
		 if($('#increPromotionUsedRatio').val().length==0)
		{
			alert('增量资源折扣率不能为空!');
			return false;
		}
		 if($('#increPromotionUsedRatio').val().indexOf(' ')>=0)
		{
			alert('增量资源折扣率不能存在空格!');
			return false;
		}
		if(isNaN($('#increPromotionUsedRatio').val()) || !numReg2.test($('#increPromotionUsedRatio').val()) )
		{
			alert('增量资源折扣率必须为0~100的数字!');
			return false;
		}
		
		 if($('#returnSourceAmount').val().length==0)
		{
			alert('年底一次性返还资源不能为空!');
			return false;
		}
		 if($('#returnSourceAmount').val().indexOf(' ')>=0)
		{
			alert('年底一次性返还资源不能存在空格!');
			return false;
		}
		if(isNaN($('#returnSourceAmount').val()) || !numReg.test($('#returnSourceAmount').val()))
		{
			alert('年底一次性返还资源大小必须为数字!');
			return false;
		}
		
		 if($('#returnSourceUsedRatio').val().length==0)
		{
			alert('年底一次性返还资源折扣率不能为空!');
			return false;
		}
		 if($('#returnSourceUsedRatio').val().indexOf(' ')>=0)
		{
			alert('年底一次性返还资源折扣率不能存在空格!');
			return false;
		}
		if(isNaN($('#returnSourceUsedRatio').val()) ||!numReg2.test($('#returnSourceUsedRatio').val()) )
		{
			alert('年底一次性返还资源折扣率必须为0~100的数字!');
			return false;
		}
		 if((parseFloat($('#fixSourceAmount').val())+parseFloat($('#floatSourceAmount').val())).toFixed(3) !=
			   (parseFloat($('#unPromotionAmount').val())+parseFloat($('#promotionAmount').val())+
			   parseFloat($('#increPromotionAmount').val())+parseFloat($('#returnSourceAmount').val())).toFixed(3))
		{
			alert('固定资源,浮动资源之和('+(parseFloat($('#fixSourceAmount').val())+parseFloat($('#floatSourceAmount').val()))+
					')不等于购买资源,赠送资源之和('+(parseFloat($('#unPromotionAmount').val())+parseFloat($('#promotionAmount').val())+
							   parseFloat($('#increPromotionAmount').val())+parseFloat($('#returnSourceAmount').val()))+')请检查!');
							   return false;
		}
		
		//有效日期不能为空判断
		if (null==promotion || ''==promotion) {
			alert('常规资源有效期不能为空!');
			return false;
		}
		if (null == increPro || ''== increPro) {
			alert('增量资源有效期不能为空!');
			return false;
		}
		if (null == returnSource || ''==returnSource) {
			alert('返还资源有效期不能为空!');
			return false;
		}
		//不能小于当前日期起判断
		 if (promotion != '') {
			if (!timeCheck(norwDate, promotion)) {
				alert('常规资源有效期不能小于当前系统时间!');
				return false;
			}		
		}
		 if (increPro != '') {
			if (!timeCheck(norwDate,increPro)) {
				alert('增量资源有效期不能小于当前系统时间!');
				return false;
			}
		}
		 if (returnSource != '') {
		 	if (!timeCheck(norwDate,returnSource)) {
				alert('返还资源有效期不能小于当前系统时间!');
				return false;
			}
		}
			$('#planTotalAmount').attr("value",parseFloat($('#fixSourceAmount').val())+parseFloat($('#floatSourceAmount').val()));
			var costSubType = $("#costSubtype").val();
			var costType = $('#costType').val(); 
			var idPrice = $('#dialog_idprice').val(); 
			$.ajax({
	           	url:"checkSourcePlan.action",
	           	data:{'costSubType':costSubType,'costType':costType,'idPrice':idPrice},
	           	datatype: "json",
	           	cache:false,	  
	           	success : function(data) { 
	           		if(data =="error")
	                {
	    				alert("媒体名称，费用类型和费用子类组合已经存在，请重新选择!");
	    			}
	    			if(data =="success"){
	    				document.forms[0].action="mediaPlanCountAddSecond.action";
	    				document.forms[0].submit();
	    			}
		        },
	           	error:function()
	        	{
	        		alert("服务器异常，请刷新后重试！");
					return false;
		        }     
	        }); 
	}
	if(m==1)
	{
		//判断特殊字符
		var myReg = /^[^@\/\'\\\"#$%&\^\*<>]+$/;
		if($('#city').val()==0)
		{
			alert('地市不能为空');
		}
		else if($('#costType').val()==0)
		{
			alert('费用类型不能为空!');
		}
		else if($("#costSubtype").val()==0)
		{
			alert('费用子类不能为空!');
		}
		else if(isNaN($('#estimated').val())  || $('#estimated').val().indexOf('.')==0)
		{
			alert('预算值必须为数字!');
		}
		else if($('#estimated').val().length==0)
		{
			alert('预算值不能为空!');
		}
		else if($('#estimated').val().indexOf(' ')>=0)
		{
			alert('预算值不能存在空格!');
		}
		else
		{
			$('#planTotalAmount').attr("value",parseFloat($('#fixSourceAmount').val())+parseFloat($('#floatSourceAmount').val()));
	    	var costSubType = $("#costSubtype").val();
			var costType = $('#costType').val(); 
			var year = $('#year').val(); 
			var city  = $('#city').val(); 
			$.ajax({
	           	url:"checkFundBudget.action",
	           	data:{'costSubType':costSubType,'costType':costType,'year':year,'city':city},
	           	datatype: "json",
	           	cache:false,	  
	           	success : function(data) { 
	           		if(data =="error")
	                {
	    				alert("年份,地市，费用类型和费用子类组合已经存在，请重新选择!");
	    			}
	    			if(data =="success"){
	    				document.forms[0].action="mediaPlanBudgetAdd.action";
	    		    	document.forms[0].submit(); 
	    			}
		        },
	           	error:function()
	        	{
	        		alert("服务器异常，请刷新后重试！");
					return false;
		        }    
	        }); 		
		}
	}
	
}

</script>
	</head>

	<body>
		<!-- 顶栏start -->
		<jsp:include page="../common/top.jsp"></jsp:include>
		<!-- 顶栏end -->




		<!-- 顶部start -->
		<div id="main">
			<div class="body">
				<!-- 导航菜单 -->
				<jsp:include page="../common/nav.jsp"></jsp:include>
				<!-- 主体 -->
				<input id="keyCostSubType" type="hidden" name="sourcePlanYe"
					value="${sourcePlanYear.costSubtype}" />
				<form id="subform" name="subform" method="post"
					enctype="multipart/form-data">
					<div id="head" style="display: none;">
						<table class="condition"
							style="font-size: 14px; font-weight: bold; text-align: center; line-height: 27px;">
							<tr>
								<td>
									<a href="#"
										style="width: 304px; height: 27px; background-image: url(<%=path%>/images/304ing1.gif); color: #ffffff; display:block; float:left; margin-left:-2px;">
										1.设置投放总量 </a>
									<a href="#"
										style="width: 304px; height: 27px; background-image: url(<%=path%>/images/304notComplete1.gif); color: #ffffff; display:block; float:left; margin-left:-7px;">
										2.设置分阶段投放计划 </a>
								</td>
							</tr>
						</table>
						<div
							style="background: url(<%=path%>/images/arrow.gif);width:30px; height: 15px; margin-left:145px;"></div>
					</div>
					<div class="main_body">
						<div id="add_div">

							<table class="table_add" style="width: 100%;">
								<tr>
									<th width="148" style="width: 150px;">
										年份：
									</th>
									<td width="226" style="width: 225px;">
										<input id="year" name="sourcePlanYear.planYear" type="text"
											class="text Wdate"
											onfocus="WdatePicker({dateFmt:'yyyy',minDate:${year}})"
											style="width: 225px;" value="${year}" />
									</td>
									<th width="77">
										&nbsp;
									</th>
									<th width="78">
										地市：
									</th>
									<td width="645">
										<s:select id="city" style="width:225px;"
											value="sourcePlanYear.city" name="sourcePlanYear.city"
											list="allProvinceList" listKey="id" listValue="datavalue"
											onchange="change('1');"></s:select>
									</td>
								</tr>
								<tr>
									<th width="148" style="width: 150px;">
										费用类型：
									</th>
									<td width="226" style="width: 225px;">
										<s:select id="costType" name="sourcePlanYear.costType"
											style="width:225px;" list="costTypeList" listKey="id"
											listValue="datavalue" headerKey="0" headerValue="请选择"
											onchange="change('2');"></s:select>
									</td>
									<th width="77">
										&nbsp;
									</th>
									<th width="148" style="width: 150px;">
										费用子类：
									</th>
									<td width="226" style="width: 225px;">
										<select id="costSubtype" name="sourcePlanYear.costSubtype"
											style="width: 225px;" onchange="costSubtySelect();">
											<option value="0">
												请选择
											</option>
										</select>
									</td>
									<th width="77">
										&nbsp;
									</th>
								</tr>
								<tr>
									<th width="148" style="width: 150px;" id="estname"></th>
									<td width="226" style="width: 225px;" id="estvalue"></td>
									<th width="77">
										&nbsp;
									</th>
								</tr>

							</table>
							<div id="list_div" style="margin: 20px">
								<table class="table_list" style="width: 100%" id="entity">


								</table>

							</div>
						</div>

						<div style="margin: 8px 0 0 0px;" id="bottom3">
							<input type="button" class="btn-title" value="   返回   "
								onclick="window.location.href='budgetList.action';" />
						</div>
						<br />
						<div style="margin: 8px 0 0 150px; display: none;" id="bottom1">
							<input type="button" class="btn-title" value="   返回   "
								onclick="window.location.href='budgetList.action';" />
							&nbsp;&nbsp;
							<input type="button" class="btn-title" value=" 下一步 "
								onclick="doSubmit('2')" />

						</div>
						<div style="margin: 8px 0 0 150px; display: none;" id="bottom2">
							<input type="button" class="btn-title" value="   返回   "
								onclick="window.location.href='budgetList.action';" />
							&nbsp;&nbsp;
							<input type="button" class="btn-title" value="   保存   "
								onclick="doSubmit('1')" />


						</div>
					</div>



				</form>
			</div>
		</div>
		<div id="dialog" title="媒体名称" style="display: none;">
			<table width="0" border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td>
						<input id="mediaName" type="text" style="width: 250px"
							class="text" />
						&nbsp;&nbsp;
						<input type="button" class="btn-title" value="搜索"
							onclick="findAllContract();" />
						<input type="reset" class="btn-title" value="重置"
							onclick="mediaNameRes();" />
					</td>
				</tr>
				<tr>
					<td>
						<select id="xiangmuId" multiple="multiple"
							style="width: 100%; height: 335px; overflow: hidden"
							ondblclick="xiangmuDBlclick();"></select>
					</td>
				</tr>

			</table>
		</div>

		<!-- 顶部end -->


		<!-- 底部start -->
		<div id="bottom">
			<div class="body">
				<label>
					版权所有&nbsp;&nbsp;&nbsp;&nbsp;2012东莞移动
				</label>
			</div>
		</div>
		<!-- 底部end -->
	</body>
</html>